# 将字符串转换为大写
words = ["hello", "world", "python", "ABCDEF", "PPT"]
upper_words = list(map(str.upper, words))
print(upper_words)  # ['HELLO', 'WORLD', 'PYTHON']

lower_words = list(map(lambda item: item.casefold(), words))
print(lower_words)


# 使用lambda函数
numbers = [1, 2, 3, 4]
squared = list(map(lambda x: x**2, numbers))
print(squared)  # [1, 4, 9, 16]

# filter函数的使用

nums = [1, 2, 3, 4, 5, 6, 7, 8, 9]

new_odd_nums = list(filter(lambda item: item % 2 == 0, nums))
print(new_odd_nums)


class Person:

    def __init__(self, name, age):
        self.name = name
        self.age = age

    def set_user_name(self, newValue):
        self.name = newValue


person = Person("linda", 20)

# dir() - 返回对象的所有属性列表
print("返回对象的所有属性列表", dir(person))  # 显示s的所有属性和方法名

print(hasattr(person, "name"))

# 通过getattr获取类的实列上的属性或者方法

print(getattr(person, "name"))

person_set_username_method = getattr(person, "set_user_name")
person_set_username_method("susan")
print(getattr(person, "name"))

setattr(person, "age", 29)  # 通过setattr设置对象的属性
print(getattr(person, "age"))

print("------", getattr(person, "job", "默认值aaa"))


# delattr删除对象属性
try:
    delattr(person, "age")
    print(getattr(person, "age"))
except AttributeError as e:
    print("异常了=", e)


# callable  判断一个对象是否为函数


# type(myFun) -><class 'function'>
def myFun():
    print("这个是一个函数")


if callable(myFun):
    print(myFun.__name__)
